package com.huawei.hianalytics.process;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.huawei.appmarket.service.alarm.control.RepeatingTaskManager;
import com.huawei.hianalytics.g.b;
import com.huawei.hianalytics.global.AutoCollectEventType;
import com.huawei.hianalytics.util.e;
import com.huawei.hianalytics.util.g;
import com.huawei.hianalytics.util.i;
import java.util.List;

public class c extends d implements HiAnalyticsInstanceEx {
    private Context b;

    c(Context context) {
        super("_instance_ex_tag");
        this.b = context;
    }

    private boolean a() {
        SharedPreferences a = e.a(this.b, "global_v2");
        boolean booleanValue = ((Boolean) e.b(a, "isFirstRun", Boolean.valueOf(false))).booleanValue();
        if (!booleanValue) {
            e.a(a, "isFirstRun", Boolean.valueOf(true));
        }
        return !booleanValue;
    }

    private boolean a(String str, String str2) {
        return (TextUtils.isEmpty(str2) || str.equals(str2)) ? false : true;
    }

    public void a(List<AutoCollectEventType> list) {
        b.b("HianalyticsSDK", "autoCollect() is executed.");
        if (!i.a().b()) {
            b.c("HiAnalytics/event", "userManager.isUserUnlocked() == false");
        } else if (list == null) {
            b.c("HianalyticsSDK", "autoCollect() eventTypes is null,End this method!");
        } else {
            b.b("HianalyticsSDK", "autoCollect() executed.");
            if (list.contains(AutoCollectEventType.APP_FIRST_RUN) && a()) {
                b.b("HianalyticsSDK", "autoCollect: APP_FIRST_RUN");
                b.a().b();
            }
            String g = com.huawei.hianalytics.a.b.g();
            String b = com.huawei.hianalytics.a.b.b();
            if (list.contains(AutoCollectEventType.APP_UPGRADE) && a(g, b)) {
                b.b("HianalyticsSDK", "autoCollect: APP_UPGRADE");
                b.a().b(g, b);
            }
            if (list.contains(AutoCollectEventType.APP_CRASH)) {
                b.b("HianalyticsSDK", "autoCollect: APP_CRUSH : true");
                b.a().a(true);
                return;
            }
            b.b("HianalyticsSDK", "autoCollect: APP_CRUSH : false");
            b.a().a(false);
        }
    }

    public void enableLogCollection(Context context, HiAnalyticsLogConfig hiAnalyticsLogConfig) {
        b.b("HianalyticsSDK", "enableLogCollection() is executed.");
        if (context != null) {
            a.b().a(context.getApplicationContext(), hiAnalyticsLogConfig);
        }
    }

    @Deprecated
    public void handleV1Cache() {
        if (i.a().b()) {
            b.b("HianalyticsSDK", "handleV1Cache() is executed.");
            b.a().a("_instance_ex_tag");
            return;
        }
        b.c("HiAnalytics/event", "userManager.isUserUnlocked() == false");
    }

    public void onStartApp(String str, String str2) {
        b.b("HianalyticsSDK", "onStartApp() is executed.");
        if (!i.a().b()) {
            b.c("HiAnalytics/event", "userManager.isUserUnlocked() == false");
        } else if (g.a(RepeatingTaskManager.KEY_PRE_DOWNLOAD_START_TYPE, str, 4096) && g.a("startCMD", str2, 4096)) {
            b.a().a(str, str2);
        } else {
            b.c("HianalyticsSDK", "onStartApp() Parameter error, please enter the correct parameter");
        }
    }

    public void refreshLogCollection(HiAnalyticsLogConfig hiAnalyticsLogConfig, boolean z) {
        b.b("HianalyticsSDK", "refreshLogCollection() is executed.");
        a.b().a(hiAnalyticsLogConfig, z);
    }
}
